package com.qf.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qf.annotation.RequiresPermissionsDesc;
import com.qf.pojo.DtsAddress;
import com.qf.pojo.DtsComment;
import com.qf.service.CommentService;
import com.qf.util.ResponseUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("/admin/comment")
public class CommentController {
    @Autowired
    private CommentService commentService;



    //http://localhost:8080/admin/comment/list?
    //page=1&limit=20&userId=1&valueId=1&sort=add_time&order=desc
    @RequiresPermissions("admin:comment:list")
    @RequiresPermissionsDesc(menu = {"商品管理","商品评论"},button = "查询")
    @GetMapping("/list")
    public Object list(@RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "20") Integer limit,
                       Integer valueId,Integer userId,String sort,String order) {

        IPage<DtsComment> iPage = commentService.findListByQuery(page,limit,valueId,userId,sort,order);

        Map data=new HashMap();
        data.put("total",iPage.getTotal());
        data.put("items",iPage.getRecords());
        return ResponseUtil.ok(data);
    }

    @RequiresPermissions("admin:comment:delete")
    @RequiresPermissionsDesc(menu = {"商品管理","商品评论"},button = "删除")
    @PostMapping("/delete")
    public Object delete(@RequestBody DtsComment dtsComment){
        commentService.deleteComment(dtsComment.getId());
        return ResponseUtil.ok();
    }



}
